<template>
  <div class="box2">
    <div class="title">
      <div>年龄构成</div>
      <img src="../../images/dataScreen-title.png" alt="" />
    </div>
    <div class="charts" ref="charts"></div>
  </div>
</template>

<script setup lang="ts">
  import { ref, onMounted } from 'vue'
  import * as echarts from 'echarts'

  let charts = ref()
  onMounted(() => {
    let myCharts = echarts.init(charts.value)
    myCharts.setOption({
      tooltip: {
        trigger: 'item',
      },
      legend: {
        top: '15%',
        right: 10,
        orient: 'vertical',
        textStyle: {
          color: 'white',
          fontSize: 18,
        },
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: ['40%', '90%'],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#fff',
            borderWidth: 2,
          },
          label: {
            show: true,
            position: 'inside',
            color: 'white',
          },
          labelLine: {
            show: false,
          },
          data: [
            { value: 1048, name: '新闻' },
            { value: 735, name: '科教' },
            { value: 580, name: '文艺' },
            { value: 484, name: '财经' },
            { value: 300, name: '体育' },
          ],
        },
      ],
      grid: {
        top: 0,
        right: 0,
        bottom: 0,
        left: 0,
      },
    })
  })
</script>

<style scoped lang="scss">
  .box2 {
    width: 100%;
    height: 100%;
    background: url(../../images/dataScreen-main-lb.png) no-repeat;
    background-size: 100% 100%;
    .title {
      div {
        color: white;
        font-size: 20px;
      }
    }
    .charts {
      margin-top: 20px;
      width: 100%;
      height: 230px;
      background: red;
    }
  }
</style>
